package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.entity.Menu;
import com.xfcy.blog.service.MenuService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 系统管理-权限资源表 (Menu)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:05
 */
@RestController
@RequestMapping("system/menu")
@Api(tags = "系统菜单管理-接口")
public class MenuController {


    @Autowired
    private MenuService menuService;

    @GetMapping("/getMenuTree")
    @SaCheckLogin
    @ApiOperation(value = "获取菜单", httpMethod = "GET",response = R.class, notes = "获取菜单")
    public R getMenuTree() {
        return menuService.getMenuTree();
    }

    @GetMapping("/getMenuApi")
    @SaCheckLogin
    @ApiOperation(value = "获取所有接口", httpMethod = "GET",response = R.class, notes = "获取所有接口")
    public R getMenuApi(Integer id) {
        return menuService.getMenuApi(id);
    }

    @OperationLogger(value = "添加菜单")
    @PostMapping(value = "/create")
    @SaCheckPermission("/system/menu/create")
    @ApiOperation(value = "添加菜单", httpMethod = "POST", response = R.class, notes = "添加菜单")
    public R createMenu(@RequestBody Menu menu) {
        return menuService.insertMenu(menu);
    }

    @OperationLogger(value = "更新菜单")
    @PostMapping("/update")
    @SaCheckPermission("/system/menu/update")
    @ApiOperation(value = "更新菜单", httpMethod = "POST", response = R.class, notes = "更新菜单")
    public R updateMenu(@RequestBody Menu menu) {
        return menuService.updateMenu(menu);
    }

    @OperationLogger(value = "删除菜单")
    @DeleteMapping(value = "/remove")
    @SaCheckPermission("/system/menu/remove")
    @ApiOperation(value = "删除菜单", httpMethod = "DELETE", response = R.class, notes = "删除菜单")
    public R deleteMenuById(Integer id) {
        return menuService.deleteMenuById(id);
    }

}

